package com.gopay.common.cps.dao.cbrmb.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.cbrmb.CbRmbAllocationOrderLogsDAO;
import com.gopay.common.domain.cbrmb.CbRmbAllocationOrderLogs;
import com.gopay.common.exception.GopayException;

@Repository("cbRmbAllocationOrderLogsDAO")
public class CbRmbAllocationOrderLogsDAOImpl extends BaseDAOImpl<CbRmbAllocationOrderLogs, Long> implements CbRmbAllocationOrderLogsDAO {

    @Override
    public List<CbRmbAllocationOrderLogs> findByGopayOrderIdAndCreateTime(String gopayOrderId, Date startTime,
            Date endTime) throws GopayException {
        String hql = "from CbRmbAllocationOrderLogs where gopayOrderId= :orderId and createTime >= :st and createTime <= :et order by createTime ASC";
        Map<String, Object> param = new HashMap<>();
        param.put("orderId", gopayOrderId);
        param.put("st", startTime);
        param.put("et", endTime);
        return super.findByHql(hql, param);
    }

    @Override
    public List<CbRmbAllocationOrderLogs> findByGopayOrderIdAndOptTypeWithCreateTime(String gopayOrderId,
            String optType, Date startTime, Date endTime) throws GopayException {
        String hql = "from CbRmbAllocationOrderLogs where gopayOrderId= :orderId and optType = :allocationOptType and createTime >= :st and createTime <= :et order by createTime ASC";
        Map<String, Object> param = new HashMap<>();
        param.put("orderId", gopayOrderId);
        param.put("allocationOptType", optType);
        param.put("st", startTime);
        param.put("et", endTime);
        return super.findByHql(hql, param);
    }
    
}
